<?php

namespace App\Http\Controllers\General\File\Traits;

use App\Models\Strator\StratorUploadLog;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

trait UploadTrait
{
    //
    public function getRandomFileName($fileExtension,$length=16):string{
        return Str::random($length).'.'.$fileExtension;
    }
    //
    public function makePublicDirectory($path):void{
        $publicDisk=Storage::disk('public');
        $publicDisk->makeDirectory($path);
    }

    //
    public function createUploadLog($strator_id,$original_name,$file_type='',$local_url='',$cloud_url=''):void{
        StratorUploadLog::create([
            'strator_id'=>$strator_id,
            'original_name'=>$original_name,
            'file_type'=>$file_type,
            'local_url'=>$local_url,
            'cloud_url'=>$cloud_url,
        ]);
    }

    //
    public function imageTypes():array{
        return [
            'jpg',
            'jpeg',
            'png',
            'gif',
            'tiff',
            'bmp',
            'webp',
        ];
    }
    //
    public function fileTypes():array{
        return [
            'doc',
            'docx',
            'xls',
            'xlsx',
            'ppt',
            'pptx',
            'pdf',
            'txt',
            'zip',
            'rar',
            '7z',
            'tar',
            'gz',
            'bz2',
            'dmg',
            'exe',
            'msi',
            'apk',
        ];
    }
    //
    public function audioTypes():array{
        return [
            'mp3',
            'wav',
            'wma',
            'aac',
            'ogg',
            'flac',
        ];
    }
    //
    public function videoTypes():array{
        return [
            'mp4',
            'avi',
            'wmv',
            'mov',
            'flv',
            'mkv',
            'rmvb',
            'rm',
            'mpeg',
            '3gp',
        ];
    }

}
